#! /bin/bash
#################################################################
# @Description: 用例名称：内存纠错，测试目的：操作系统支持DDR4、DDR5等内存上的ECC查错、纠错
# @Date : 2023-11-22
# @Last Modified by :
# @Last Modified time:2023-11-25
#################################################################
set -euo pipefail
res=0
#前置条件
yum install -y make gcc gcc-c++ >/dev/null
#开始测试
echo "1.检查CONFIG_RAS配置"
cat /boot/config-$(uname -r) |grep "CONFIG_RAS=y" || res=1

echo "2.解压编译测试工具ras-tools-master.zip"
unzip ras-tools-master.zip
cd ras-tools-master
make 1>/dev/null || res=1
modprobe einj || res=1
echo "3.清除dmesg日志信息"
dmesg -c
echo "4.执行构造内存错误"
./einj_mem_uc || res=1
echo "5.检查dmesg日志"
dmesg | grep Recovered || res=1

# 判断用例是否执行成功
[ "$res" = "0" ] && echo -e "\033[32m-----------------test PASSED----------------\033[0m" || echo -e "\033[31m-----------------test FAILD----------------\033[0m"
echo "测试完成，环境清理"
modprobe -r einj
cd ..
rm -rf ras-tools-master